package com.camemax.nginx.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class NginxController {
    @Value("${server.port}")
    private String port;

    @GetMapping("/test")
    public Map<String, Object> getNginxRequest(HttpServletRequest servletRequest) {
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("url", servletRequest.getRequestURL());
        requestMap.put("port", port);
        requestMap.put("LocalPort", servletRequest.getLocalPort()); // 获取服务器URL端口
        requestMap.put("RemotePort", servletRequest.getRemotePort()); // 获取服务器应用（假如多服务器代理，取最后一个代理服务器）端口
        requestMap.put("ServerPort", servletRequest.getServerPort()); // 获取客户端请求URL时的端口
        return requestMap;
    }
}